﻿using System;
using System.Threading;

namespace Trader
{
   [Serializable]
    public abstract class Order
    {
        string trader;
        string instrument;
        string buySell;
        string orderType;
        double price;
        int quantity;
        static long globalOrderId;
        long orderId;
        DateTime orderTimeStamp;

        public Order()
        {
            //Generate Default Values 
            //Global unique order ID
            orderId = Interlocked.Increment(ref globalOrderId);
            //Order Time Stamp
            orderTimeStamp = DateTime.Now;
        }

        public Order(string id, string service, string orderType, string buySell, double price, int quantity)
        {
           this.trader = id;
           this.instrument = service;
           this.orderType = orderType;
           this.buySell = buySell;
           this.price = price;
           this.quantity = quantity;
               
        }

        public DateTime TimeStamp
        {
            get { return orderTimeStamp; }
        }

        public string TraderID
        {
           get { return trader; }
           set { trader = value; }
        }

        public string Instrument
        {
            get { return instrument; }
            set { instrument = value; }
        }

        public string OrderType
        {
            get { return orderType; }
            set { orderType = value; }
        }

        public string BuySell
        {
            get { return buySell; }
            set { buySell = value; }
        }

        public double Price
        {
            get { return price; }
            set { price = value; }
        }

        public int Quantity
        {
            get { return quantity; }
            set
            {
                if (value < 0)
                    quantity = 0;
                else
                    quantity = value;
            }
        }

        public long OrderID
        {
            get { return orderId; }
            set { orderId = value; }
        }

        public override string ToString()
        {
           string print = trader + " " + instrument + " " + OrderType + " " + buySell + " " + quantity.ToString() + " " + Price.ToString();
           return print;
        }
    }
}
